package packaged.storage;

import play.Play;

public class Keeper {
    static Storage storage = initStorage();

    private static Storage initStorage() {
        switch (Play.configuration.getProperty("storage.position")) {
            case "0":
                return new LocalStorage();
            case "1":
                return new RedisStorage();
            default:
                return null;
        }
    }

    public static void add(String key, String val) {
        storage.add(key, val);
    }

    public static void set(String key, String val) {
        storage.set(key, val);
    }

    public static void set(String key, String val, String overtime) {
        storage.set(key, val, overtime);
    }

    public static void set(String key, String val, int overtime) {
        storage.set(key, val, overtime);
    }

    public static String get(String key) {
        return storage.get(key);
    }

    public static String get(String key, String spare) {
        return storage.get(key, spare);
    }

    public static void del(String key) {
        storage.del(key);
    }

    public static boolean has(String key) {
        return get(key) != null;
    }


    public static void exp(String key) {
        storage.exp(key);
    }

    public static void exp(String key, String overtime) {
        storage.exp(key, overtime);
    }

    public static void exp(String key, int overtime) {
        storage.exp(key, overtime);
    }
}
